from mmcv.runner import HOOKS, Hook
import os


@HOOKS.register_module()
class Delete_file_Hook(Hook):
    def __init__(self, path):
        self.path = path
        pass

    def before_run(self, runner):
        logger = runner.logger
        self.path = self.path.split("/")
        filename_index = self.path[-1]
        path = "/".join(self.path[:-1])
        delete_filename = os.path.join(path, f"data{filename_index}.txt")
        if os.path.exists(delete_filename):
            os.remove(delete_filename)
            logger.info("delete assigner customized log file\n")
        else:
            logger.info("no such file\n")
        pass

    def after_run(self, runner):
        pass

    def before_epoch(self, runner):
        pass

    def after_epoch(self, runner):
        pass

    def before_iter(self, runner):
        pass

    def after_iter(self, runner):
        pass
